home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / algrtest / multiply.s < prev    next >
Text File  |  1985-11-19  |  5KB  |  128 lines

  1.  ; Program Name: MULTIPLY.S
  2.  ;      Version: 1.003
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in PC-relative mode and save with a TOS extension.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;     Execute from the desktop; or execute SPAWN.TTP, type MULTIPLY.TOS on
  11.  ; its command line and view this program's output in MULTIPLY.DAT.
  12.  
  13.  ; Program Function:
  14.  
  15.  ;     Measures the speed of multiplication algorithms.
  16.  
  17. calculate_program_size:
  18.  lea        -$102(pc), a1       ; Fetch basepage start address.  
  19.  lea        program_end, a0     ; Fetch program end address.
  20.  trap       #6                  ; Return unused memory to op system.
  21.  
  22. print_heading:
  23.  lea        heading, a0
  24.  bsr        print_string
  25.  
  26. the_mulu_instruction:
  27.  lea        header_1, a0 
  28.  bsr        print_string
  29.  move.l     #49999, d7          ; D7 is counter for the loop.
  30.  trap       #3                  ; Fetch start time.
  31.  move.l     d0, d3              ; Save start_time in D3.
  32. mulu_loop:                      ; Marks start of instruction in the loop.
  33.  mulu       #5, d0              ; Instruction in the loop.
  34. memory_1:                       ; Marks end of instruction in the loop.
  35.  dbra       d7, mulu_loop       ; Loop 50000 times.
  36.  trap       #3                  ; Fetch end time.
  37.  sub.l      d3, d0              ; Subtract start time from end time.
  38.  trap       #10                 ; Convert to decimal milliseconds and print.
  39.  
  40. addition:
  41.  lea        header_2, a0     
  42.  bsr.s      print_string
  43.  move.l     #49999, d7          ; D7 is counter for the push loop.
  44.  trap       #3                  ; Fetch start time.
  45.  move.l     d0, d3              ; Save start_time in D3.
  46. addition_loop:                  ; Marks start of instruction in the loop.
  47.  move.l     d0, d2              ; To add one.   
  48.  add.l      d0, d0              ; To double to two.
  49.  add.l      d0, d0              ; To double to four.
  50.  add.l      d2, d0              ; To complete multiplication by 5.
  51. memory_2:                       ; Marks end of instruction in the loop.
  52.  dbra       d7, addition_loop   ; Loop 50000 times.
  53.  trap       #3                  ; Fetch end time.
  54.  sub.l      d3, d0              ; Subtract start time from end time.
  55.  trap       #10                 ; Convert to decimal milliseconds and print.
  56.  
  57. shift_and_add:
  58.  lea        header_3, a0     
  59.  bsr.s      print_string
  60.  move.l     #49999, d7          ; D7 is counter for the push loop.
  61.  trap       #3                  ; Fetch start time.
  62.  move.l     d0, d3              ; Save start_time in D3.
  63. shift_loop:                     ; Marks start of instruction in the loop.
  64.  move.l     d0, d2              ; Save a copy to add.
  65.  asl.l      #2, d0              ; Shift to multiply by 4. 
  66.  add.l      d2, d0              ; To complete multiplication by 5.
  67. memory_3:                       ; Marks end of instruction in the loop.
  68.  dbra       d7, shift_loop      ; Loop 50000 times.
  69.  trap       #3                  ; Fetch end time.
  70.  sub.l      d3, d0              ; Subtract start time from end time.
  71.  trap       #10                 ; Convert to decimal milliseconds and print.
  72.  
  73. print__mulu_requisite_memory:
  74.  lea        header_4, a0
  75.  bsr.s      print_string
  76.  lea        memory_1, a0        ; Calculate number of bytes occupied by the
  77.  lea        mulu_loop, a1       ; instruction in the loop.
  78.  bsr.s      print_requisite_memory
  79.  
  80. print_addition_requisite_memory:
  81.  lea        header_5, a0
  82.  bsr.s      print_string
  83.  lea        memory_2, a0        ; Calculate number of bytes occupied by the
  84.  lea        addition_loop, a1   ; instruction in the loop.
  85.  bsr.s      print_requisite_memory
  86.  
  87. print_shift_and_add_requisite_memory:
  88.  lea        header_6, a0
  89.  bsr.s      print_string
  90.  lea        memory_3, a0        ; Calculate number of bytes occupied by the
  91.  lea        shift_loop, a1      ; instruction in the loop.
  92.  bsr.s      print_requisite_memory
  93.  
  94. terminate:
  95.  trap       #8
  96.  
  97.  ; SUBROUTINES
  98.  
  99. print_requisite_memory:
  100.  suba.l     a1, a0
  101.  move.l     a0, d1
  102.  trap       #4                  ; Returns address of decimal string in A0.
  103.  bsr.s      print_string
  104.  lea        header_7, a0
  105.  bsr.s      print_string
  106.  rts
  107.  
  108. print_string:                   ; Expects address of string to be in A0.
  109.  pea        (a0)                ; Push address of string onto stack.
  110.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  111.  trap       #1                  ; GEMDOS call
  112.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  113.  rts
  114.  
  115.  data
  116. heading:      dc.b   "MULTIPLY Execution Results",$D,$A,$D,$A,0
  117. header_1:     dc.b       "   MULU time:                    ",0
  118. header_2:     dc.b       "   Addition time:                ",0
  119. header_3:     dc.b       "   Shift and add time:           ",0
  120. header_4:     dc.b $D,$A,"   MULU requisite memory:           ",0
  121. header_5:     dc.b       "   Addition requisite memory:       ",0
  122. header_6:     dc.b       "   Shift and add requisite memory:  ",0
  123. header_7:     dc.b       "  bytes",$D,$A,0
  124.  bss
  125.  align                        
  126. program_end:  ds.l      0  
  127.  end
  128.